﻿using System;
using System.Collections.Generic;
using Common;
using System.Web.Script.Serialization;
using Educational.Business;
using Basic.Business;
using Educational.VO;

public partial class Educational_Ajax_SchoolRoleManage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //强制刷新页面
        Response.Buffer = true;
        Response.ExpiresAbsolute = System.DateTime.Now.AddSeconds(-1);
        Response.Expires = 0;
        Response.CacheControl = "no-cache";
        Response.AppendHeader("Pragma", "No-Cache");

        JavaScriptSerializer json = new JavaScriptSerializer();
        if (!String.IsNullOrEmpty(Request.QueryString["Action"]))
        {
            string action = BadChar.ReplaceBadChar(Request.QueryString["Action"]);
            switch (action)
            {
                #region deleteSchoolRoleGroup删除权限组
                case "deleteSchoolRoleGroup":
                    {
                        Result<Object> result = new Result<Object>();
                        try
                        {
                            if (!SchoolAdmin.IsSchoolSessionValid())
                                throw new Exception("您的登录已超时，请重新登录！");
                            //School school = (School)Session["school"];
                            //int schoolRoleGroupId = int.Parse(Request.QueryString["schoolRoleGroupId"]);
                            //SchoolRoleGroupAdmin.DeleteSchoolRoleGroup(school.schoolId, schoolRoleGroupId);
                            result.error = false;
                            result.msg = "删除权限组成功";
                        }
                        catch (Exception ex)
                        {
                            result.error = true;
                            result.msg = ex.Message;
                        }
                        Response.Write(json.Serialize(result));
                    }
                    break;
                #endregion
                #region saveUpdateSchoolRoleGroup保存权限组修改
                case "saveUpdateSchoolRoleGroup":
                    {
                        Result<Object> result = new Result<Object>();
                        try
                        {
                            if (!SchoolAdmin.IsSchoolSessionValid())
                                throw new Exception("您的登录已超时，请重新登录！");
                            //School school = (School)Session["school"];
                            //int schoolRoleGroupId = int.Parse(Request.Form["schoolRoleGroupId"]);
                            //string schoolRoleGroupName = BadChar.ReplaceBadChar(Request.Form["schoolRoleGroupName"].Trim());
                            //if (schoolRoleGroupName.Equals(""))
                            //    throw new Exception("权限组名称不能为空");
                            //int leaderId = int.Parse(Request.Form["leaderId"]);
                            //int gradeId = int.Parse(Request.Form["gradeId"]);
                            //int status = int.Parse(Request.Form["status"]);
                            //SchoolRoleGroupAdmin.UpdateSchoolRoleGroup(schoolRoleGroupId, school.schoolId, gradeId, leaderId, status, schoolRoleGroupName); ;
                            result.error = false;
                            result.msg = "修改权限组成功";
                        }
                        catch (Exception ex)
                        {
                            result.error = true;
                            result.msg = ex.Message;
                        }
                        Response.Write(json.Serialize(result));
                    }
                    break;
                #endregion
                #region saveAddSchoolRoleGroup保存权限组添加
                case "saveAddSchoolRoleGroup":
                    {
                        Result<Object> result = new Result<Object>();
                        try
                        {
                            if (!SchoolAdmin.IsSchoolSessionValid())
                                throw new Exception("您的登录已超时，请重新登录！");
                            //School school = (School)Session["school"];
                            //string schoolRoleGroupName = BadChar.ReplaceBadChar(Request.Form["schoolRoleGroupName"].Trim());
                            //if (schoolRoleGroupName.Equals(""))
                            //    throw new Exception("权限组名称不能为空");
                            //int departmentId = int.Parse(Request.Form["departmentId"]);
                            //int schoolRoleGroupId = int.Parse(Request.Form["schoolRoleGroupId"]);
                            //SchoolRoleGroupAdmin.AddSchoolRoleGroup(school.schoolId, departmentId, schoolRoleGroupId, schoolRoleGroupName);
                            result.error = false;
                            result.msg = "添加权限组成功";
                        }
                        catch (Exception ex)
                        {
                            result.error = true;
                            result.msg = ex.Message;
                        }
                        Response.Write(json.Serialize(result));
                    }
                    break;
                #endregion
                #region search查询列表
                case "search":
                    {
                        Result<SchoolRoleCategory> result = new Result<SchoolRoleCategory>();
                        try
                        {
                            if (!SchoolAdmin.IsSchoolSessionValid())
                                throw new Exception("您的登录已超时，请重新登录！");
                            IList<SchoolRoleCategory> data = SchoolRoleCategoryAdmin.GetsSchoolRoleCategory();
                            result.data = data;
                            result.page = 1;
                            result.error = false;
                            result.msg = "查询权限组列表成功";
                        }
                        catch (Exception ex)
                        {
                            result.error = true;
                            result.msg = ex.Message;
                        }
                        Response.Write(json.Serialize(result));
                    }
                    break;
                #endregion
                default:
                    {
                        Result<object> result = new Result<object>();
                        result.error = true;
                        result.msg = StringTable.ErrorUnknowAction;
                        Response.Write(json.Serialize(result));
                    }
                    break;
            }
        }
        else
        {
            Result<object> result = new Result<object>();
            result.error = true;
            result.msg = StringTable.ErrorMissingParameters;
            Response.Write(json.Serialize(result));
        }
        Response.End();
    }
}
